// 引入koa-router
const Router = require('koa-router')
// 引入上传头像utils
const avatarUpload = require('../../utils/upload/avatarUpload')
// 引入上传轮播图utils
const swiperUpload = require('../../utils/upload/swiperUploadUtils')
// 引入上传广告图utils
const adUpload = require('../../utils/upload/adUploadUtils')
// 引入博客封面utils
const blogfaceload = require('../../utils/upload/blogfaceUploadUtils')
const { avatarImgUpload, swiperImgUpload,adImgUpload, blogFaceLoad,//各类图片上传处理函数
        delAvatarImgUpload, delSwiperUpload, delAdUpload,delBlogFaceLoad,//各类图片删除处理函数
        getSwipers,getAds,//各类获取图片处理函数
        sureAddSwiper,sureAddAd, //各类确认上传到数据库处理函数
        blogFaceErr
    } = require('../../controller/upload.controller')
// 创建实例
// prefix在路由地址前缀加上默认地址
const router = new Router({ prefix:'/api/upload' })

// 上传头像图片
router.post('/avatarupload', avatarUpload.single('file'), avatarImgUpload)
// 删除头像图片
router.post('/delavatarupload', delAvatarImgUpload)

// 上传轮播图图片
router.post('/swiperupload', swiperUpload.single('file'), swiperImgUpload)
// 删除轮播图图片
router.post('/delswiperupload', delSwiperUpload)
// 获取轮播图图片
router.post('/getswipers', getSwipers)
// 确认添加轮播图进数据库
router.post('/sureaddswiper', sureAddSwiper)

// 上传广告图片
router.post('/adupload', adUpload.single('file'), adImgUpload)
// 删除广告图片
router.post('/deladupload', delAdUpload)
// 确认添加广告图进数据库
router.post('/sureaddad', sureAddAd)
// 获取广告图
router.post('/getads', getAds)

// 上传博客封面
router.post('/blogfaceload', blogFaceErr, blogFaceLoad)
// 删除广告图片
router.post('/delblogfaceload', delBlogFaceLoad)
module.exports = router